//
//  MLSTransCell.swift
//  MLSMircoBlog
//
//  Created by 袁航 on 15/8/3.
//  Copyright © 2015年 yuanhang. All rights reserved.
//

import UIKit
private let originalTextFont: CGFloat = 14
class MLSTransCell: MLSStatusCell {
    
    override var status: MLSUserStatus? {
        didSet {
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            originalText.text = "@" + name + ":" + text
        }
    }
    
    override func setupUI() {
        super.setupUI()
        // 插入控件
        contentView.insertSubview(centerButton, belowSubview: pictureView)
        contentView.insertSubview(originalText, aboveSubview: centerButton)
        // 设置布局
        centerButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: detailLabel, size: nil, offset: CGPoint(x: -separatorMargin, y: separatorMargin))
        centerButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil,offset: CGPoint(x: 0, y: -separatorMargin))
        // 原作者文本布局
        originalText.ff_AlignInner(type: ff_AlignType.TopLeft, referView: centerButton, size: nil, offset: CGPoint(x: separatorMargin, y: separatorMargin))
        // 4> 图片视图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: originalText, size: CGSize(width: 280, height: 280), offset: CGPoint(x: 0, y: separatorMargin))
        pictureViewHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureViewWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewTopCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)
    }
    
    
    // 懒加载控件
    private lazy var centerButton: UIButton = {
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        return button
    }()
    private lazy var originalText: FFLabel = {
        let label = FFLabel(color: UIColor.darkGrayColor(), fontSize: originalTextFont)
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2 * separatorMargin
        label.numberOfLines  = 0
        return label
    }()
}
